//
//  Ugc_Receive_TbvCell_WX.m
//  ZITHER
//
//  Created by weixin on 2018/9/26.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "Ugc_Receive_TbvCell_WX.h"
#define kGAP 10
#define kAvatar_Size 40

@implementation Ugc_Receive_TbvCell_WX

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
//    self.backgroundColor = [UIColor randomColor];
    
    [self setBorderWithHiddem:NO Color:[UIColor colorWithHex:@"eeeeee"] width:1 Radius:0];
    
    [self.viewBorder mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.left.equalTo(self).offset(0);
        make.right.equalTo(self).offset(0);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    [self setUI];

    [self defaultConfiguration];

    [self massonry];
    
}

-(void)setUI{
    
    [self addSubview:self.labMsgStatus];
    [self addSubview:self.PicUser];
    [self addSubview:self.labUserName];
    [self addSubview:self.labContent];
    [self addSubview:self.time];
    
    //右边布局 优先顺序 该创作已删除  图片 内容
    [self addSubview:self.picUgc];
//    [self addSubview:self.del1];
//    [self addSubview:self.del2];
    [self addSubview:self.labUgcContent];
    
    [self addSubview:self.labUgcContentDel];
    
}

-(void)defaultConfiguration{
    
//    self.PicUser.backgroundColor = [UIColor randomColor];
    
//    self.labUserName.text =@"黄四郎";
    self.labUserName.font =  [UIFont fontWithName:@"PingFangSC-Medium" size:14];
    self.labUserName.textColor = [UIColor colorWithHex:@"333333"];
    
//    self.labContent.text =@"";
    self.labContent.textColor = [UIColor colorWithHex:@"333333"];
    self.labContent.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
    self.labContent.numberOfLines = 6;


//    self.time.text =@"3分钟";
    self.time.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
    self.time.textColor = [UIColor colorWithHex:@"999999"];


//    self.del1.text =@"该创作";
//    self.del1.font = [UIFont systemFontOfSize:12];
//    self.del1.textColor = baseColorLight;
//
//
//    self.del2.text =@"已删除";
//    self.del2.font = [UIFont systemFontOfSize:12];
//    self.del2.textColor = baseColorLight;


    
    self.labUgcContent.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
    self.labUgcContent.numberOfLines = 5;
    
    [self.PicUser setCornerRadiusWithRadius:20 isMasks:YES];
//    self.picUgc.backgroundColor = [UIColor randomColor];
    
    self.labMsgStatus.font = [UIFont fontWithName:@"PingFangSC-Medium" size:17];
    
    self.labUgcContent.backgroundColor = [UIColor colorWithHex:@"f5f5f5"];

    
}


-(void)massonry{
    
    [self.labMsgStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.left.equalTo(self).offset(14);
    }];
    
    
    [self.PicUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labMsgStatus.mas_bottom).offset(15);
        make.left.equalTo(self).offset(14);
        make.height.width.mas_equalTo(40);
//        make.bottom.equalTo(self).offset(-80);
    }];
//    self.self.labUserName.hidden = YES;

    [self.labUserName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.PicUser.mas_top).offset(2);
        make.left.equalTo(self.PicUser.mas_right).offset(12);
    }];
//    self.labContent.hidden = YES;

    //最多6航
    [self.labContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.time.mas_bottom).offset(8);
        make.left.equalTo(self.PicUser.mas_right).offset(12);
        make.right.equalTo(self).offset(-95);
        make.bottom.equalTo(self).offset(-30);
    }];
    
//    self.time.hidden = YES;
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.PicUser.mas_bottom).offset(0);
        make.left.equalTo(self.PicUser.mas_right).offset(12);
        make.height.mas_equalTo(12);
    }];
//    self.del1.hidden = YES;
//    [self.del1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.PicUser.mas_top).offset(0);
//        make.right.equalTo(self).offset(-14);
//        make.width.mas_equalTo(60);
//    }];
//    self.del2.hidden = YES;
//    [self.del2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.del1.mas_bottom).offset(5);
//        make.right.equalTo(self).offset(-14);
//        make.width.mas_equalTo(60);
//    }];
//    self.labUgcContent.hidden = YES;
    [self.labUgcContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.PicUser.mas_top).offset(0);
        make.right.equalTo(self).offset(-14);
        make.width.mas_equalTo(80);
    }];
    
    [self.labUgcContentDel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.PicUser.mas_top).offset(0);
        make.right.equalTo(self).offset(-14);
        make.height.width.mas_equalTo(80);
    }];
    
//    self.picUgc.hidden = YES;
    [self.picUgc mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.PicUser.mas_top).offset(0);
        make.right.equalTo(self).offset(-14);
        make.height.width.mas_equalTo(80);
    }];
    
    
//
//
//    //右边布局 优先顺序 该创作已删除  图片 内容
//    @property (weak, nonatomic) IBOutlet UILabel *del1;
//    @property (weak, nonatomic) IBOutlet UILabel *del2;
//
//    @property (weak, nonatomic) IBOutlet UIImageView *picUgc;
//
//    @property (weak, nonatomic) IBOutlet UILabel *labUgcContent;
}


-(UIImageView *)PicUser{
    if (!_PicUser) {
        _PicUser = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _PicUser.contentMode = 2;
        [_PicUser setCornerRadiusWithRadius:20 isMasks:YES];
        _PicUser.clipsToBounds = YES;
    }
    return _PicUser;
}

-(UIImageView *)picUgc{
    if (!_picUgc) {
        _picUgc = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _picUgc.contentMode = 2;
        [_picUgc setCornerRadiusWithRadius:4 isMasks:YES];
        _PicUser.clipsToBounds = YES;
    }
    return _picUgc;
}

-(UILabel *)labUserName{
    if (!_labUserName) {
        _labUserName = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _labUserName;
}
-(UILabel *)labContent{
    if (!_labContent) {
        _labContent = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _labContent;
}
-(UILabel *)time{
    if (!_time) {
        _time = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _time;
}
-(UILabel *)del1{
    if (!_del1) {
        _del1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _del1;
}
-(UILabel *)del2{
    if (!_del2) {
        _del2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _del2;
}

-(UILabel *)labUgcContent{
    if (!_labUgcContent) {
        _labUgcContent = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        [_labUgcContent setCornerRadiusWithRadius:4 isMasks:YES];
    }
    return _labUgcContent;
}

-(UILabel *)labMsgStatus{
    if (!_labMsgStatus) {
        _labMsgStatus = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
       _labMsgStatus.font = [UIFont fontWithName:@"Helvetica-Bold" size:22];
    }
    return _labMsgStatus;
}

-(UILabel *)labUgcContentDel{
    if (!_labUgcContentDel) {
        _labUgcContentDel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _labUgcContentDel.text = @"创作已删除";
        _labUgcContentDel.textAlignment = 1;
        _labUgcContentDel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
        _labUgcContentDel.backgroundColor = [UIColor colorWithHex:@"d8d8d8"];
        [_labUgcContentDel setCornerRadiusWithRadius:4 isMasks:YES];
    }
    return _labUgcContentDel;
}

-(void)setTypeMsgStatus:(NSString *)typeMsgStatus{
    _typeMsgStatus = typeMsgStatus;
    NSLog(@"labMsgStatus === %@",typeMsgStatus);
    self.labMsgStatus.text = typeMsgStatus;
    if (typeMsgStatus.length == 0) {
        self.labMsgStatus.hidden = YES;
        [self.PicUser mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.labMsgStatus.mas_bottom).offset(0);
        }];
    }else{
        [self.PicUser mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.labMsgStatus.mas_bottom).offset(15);
        }];
        self.labMsgStatus.hidden = NO;
    }
}

-(void)setModelSon:(UgcReceiveModelSon *)modelSon{
    _modelSon = modelSon;
    
    NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,modelSon.sendAvatar];
    [self.PicUser sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"ucg_img_loding"]];
    
    self.labUserName.text = modelSon.sendNickName;
    
    /** 消息类型（1:点赞  2:评论 3:回复评论）*/
    if ([modelSon.msgType isEqualToString:@"1"]) {
        self.labContent.text = @"赞了你的创作";
        self.labContent.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15];
        [self.labContent mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-45);
        }];
    }else{
        self.labContent.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
        [self configComment:modelSon.msgType];
    }
    
    self.time.text = [modelSon.createTime convertCurrentTime];
    
    
    if ([modelSon.delStatus isEqualToString:@"0"]) {
        self.labUgcContentDel.hidden = NO;
        self.picUgc.hidden = YES;
        self.labUgcContent.hidden = YES;
    }else if ([modelSon.delStatus isEqualToString:@"1"]){
        self.labUgcContentDel.hidden = YES;
        if ([modelSon.contentType isEqualToString:@"1"]) {
            self.picUgc.hidden = NO;
            self.labUgcContent.hidden = YES;
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,modelSon.content];
            [self.picUgc sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"ucg_img_loding"]];
            
        }else if ([modelSon.contentType isEqualToString:@"0"]){
            self.picUgc.hidden = YES;
            self.labUgcContent.hidden = NO;
            self.labUgcContent.text = modelSon.content;
//            [self textLeftTopAlign];
        }
    }
    
    
//    /** 消息状态（0：未查看， 1：已查看）*/
//    @property (nonatomic, copy) NSString *msgStatus;
//
//    /** 详情页 ID */
//    @property (nonatomic, copy) NSString *relId;
//
//    /** 跳转到个人主页 ID */
//    @property (nonatomic, copy) NSString *sendUserId;
    



}



/** type(2: 评论创作 3: 回复其他人) */
-(void)configComment:(NSString*)type{
    
    //两种状态 一种自己回复 一种是回复其他人
    NSString *str = nil;
    if ([type isEqualToString:@"2"]){
        //不需要展示回复人
        str= [NSString stringWithFormat:@"评论了你的创作  %@",self.modelSon.msg];
        
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *muStyle = [[NSMutableParagraphStyle alloc] init];
        
        if ([text.string isMoreThanOneLineWithSize:CGSizeMake(kScreenW-kGAP-kAvatar_Size-2*kGAP, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpaceing:5.0]) {//margin
            muStyle.lineSpacing = 5.0;//设置行间距离
        }else{
            muStyle.lineSpacing = CGFLOAT_MIN;//设置行间距离
        }
        
        [text addAttribute:NSParagraphStyleAttributeName value:muStyle range:NSMakeRange(0, text.length)];
        
        [text addAttribute:NSForegroundColorAttributeName
                     value:[UIColor blackColor]
                     range:NSMakeRange(0, 7)];
        [text addAttribute:NSFontAttributeName
                     value:[UIFont fontWithName:@"PingFangSC-Medium" size:15]
                     range:NSMakeRange(0,7)];
        
        self.labContent.attributedText = text;
    }else if ([type isEqualToString:@"3"]){
        str= [NSString stringWithFormat:@"回复你的评论  %@",self.modelSon.msg];
        
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *muStyle = [[NSMutableParagraphStyle alloc] init];
        
        if ([text.string isMoreThanOneLineWithSize:CGSizeMake(kScreenW-kGAP-kAvatar_Size-2*kGAP, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpaceing:5.0]) {//margin
            muStyle.lineSpacing = 5.0;//设置行间距离
        }else{
            muStyle.lineSpacing = CGFLOAT_MIN;//设置行间距离
        }
        
        [text addAttribute:NSParagraphStyleAttributeName value:muStyle range:NSMakeRange(0, text.length)];
        
        [text addAttribute:NSForegroundColorAttributeName
                     value:[UIColor blackColor]
                     range:NSMakeRange(0, 6)];
        [text addAttribute:NSFontAttributeName
                     value:[UIFont fontWithName:@"PingFangSC-Medium" size:15]
                     range:NSMakeRange(0,6)];
        
        self.labContent.attributedText = text;
    }
    
//    self.labContent.font =
//    self.time.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
    
    if (str.length>15) {
        //最多6航
        [self.labContent mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-30);
        }];
    }else{
        //最多6航
        [self.labContent mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-45);
        }];
    }

    
}

-(BaseView *)labMsgStatusBackGround{
    if (!_labMsgStatusBackGround) {
        _labMsgStatusBackGround = [[BaseView alloc]initWithFrame:CGRectMake(0, 0, 0, 0 )];
    }
    return _labMsgStatusBackGround;
}


@end
